# 2024/1/30 15:35 HFL
import hashlib

import requests, json, re
import unittest
from ddt import ddt, file_data
import allure

from common.MD5 import md5
from conf.serverip import serverip


@ddt
class chongzhi(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.token = None

    @classmethod
    def tearDownClass(cls):
        pass

    def test_Aproducttoken(self):
        url = 'http://{}/stock/producttoken'.format(serverip)
        result = requests.get(url=url)
        result.encoding = 'utf-8'
        result = json.loads(result.text)
        md5.token = result['msg']


    @file_data('D:\Python_学习\pytest_requests\data\data.yaml')
    def test_Bchongzhiapi(self, data,exp):
        url = 'http://{}/stock/asynRecharge'.format(serverip)
        while 2 :
            if data['token'] is None:
                token = md5('12345655')
                data['token'] = token
            break
        headers = {'Content-Type': 'application/json'}
        res = requests.post(url=url, json=data, headers=headers)
        res.encoding = 'unicode-escape'
        res = json.loads(res.text)
        self.assertEqual(exp['ass'], res['msg'])


if __name__ == '__main__':
    unittest.main()
